package com.example.beauty.contact;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.example.beauty.db.gen.DaoMaster;
import com.example.beauty.db.gen.DaoSession;

/**
 * 用于初始化GreenDao框架的数据库
 */

public class GreenDaoManager {
    private static DaoSession daoSession;

    /**
     *  配置数据库
     */
    public static void InitDao(Context context, String dbName){
        //创建数据库
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context,dbName,null);
        //获取可写数据库
        SQLiteDatabase db = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(db);
        //获取Dao对象管理者
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoSession(){
        return daoSession;
    }
}
